define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'card/user/index' + "/appId/" + Config.appId + location.search  ,
                    add_url: 'card/user/add',
                    edit_url: 'card/user/edit' + "/appId/" + Config.appId + "/userid/{rows.userid}",
                    del_url: 'card/user/del' + "/appId/" + Config.appId ,
                    table: 'card',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'userid',
                sortName: 'userid',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'userid', title: __('用户账户')},
                        {field: 'password', title: __('用户密码'), operate: 'LIKE'},
                        {field: 'usepassword', title: __('启用密码'), searchList: {"0": __('关闭'), "1":__('启用')}, formatter: Table.api.formatter.status},
                        {field: 'enable', title: __('Status'), searchList: {"0": __('停用'), "1":__('正常')}, formatter: Table.api.formatter.status},
                        {field: 'disabledate', title: __('到期时间'), formatter: function(v, row, index) {
							return row.disabledate + " " + row.disabletime
                        }},
                        {field: 'autodisable', title: __('到期停用'), searchList: {"0": __('否'), "1":__('是')}, formatter: Table.api.formatter.status},
                        {field: 'is_expire', title: __('是否到期'), searchList: {"0": __('否'), "1":__('是')}, custom: {"0": 'green', "1": 'red'},formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        del: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});